<template>
	<view style="">
		
		<view class="all_project_head_btn" style="">
			<project-button :projectId="project_id" stageName="整改复查记录表"></project-button>
			<step-button :approvalLog="addFormData.approval_log" :processList="stepProcessList"
				v-if="addFormData.approval_log != null"></step-button>
		</view>
		
		<view style="padding-bottom: 200rpx;">
			<!-- 项目名称 -->
			<view class="info_item" style="border: 0;">
				<text class="all_text_title">项目名称</text>
				<textarea disabled v-model="S_project_name" maxlength="-1"
				:class="true?'all_new_input_disable_style':'all_new_input_style'"
					auto-height="true" style="width: 95%;padding: 18rpx;"
					 />
			</view>
			<!-- 复查人员 -->
			<view class="info_item" style="border: 0;">
				<text class="all_text_title">复查人员</text>
				<input
					style="margin-top: 39rpx;"
					placeholder-style="font-size:30rpx"
					:disabled="!isSubmit"
					v-model="addFormData.notifier"
					:class="!isSubmit?'all_new_input_disable_style':'all_new_input_style'"
				/>
			</view>
			<!-- 复查时间 -->
			<view class="info_item" style="position: relative;border: 0;">
				<text class="all_text_title">复查时间</text>
				<picker :disabled="!isSubmit" mode="date" @change="setDate" class="picker1">
					<view :class="!isSubmit?'all_new_input_disable_style':'all_new_input_style'">{{ date }}</view>
				</picker>
				<image src="../../../../static/project/date.png" class="date"></image>
			</view>
			<!-- 整改通知 -->
			<view
				class="info_item"
				style="border-bottom: 0;"
			>
				<text class="all_text_title">根据贵单位出具的整改意见和回复，我公司组织评价人员对贵公司已整改问题进行了现场复查，复查情况如下：</text>
				<textarea
					v-model="addFormData.existing_problems"
					class="textera"
					:disabled="!isSubmit"
					maxlength="-1"
					auto-height="true"
				/>
			</view>
			<!-- 附件上传提示 -->
			<view class="info_item" style="border-bottom: 0; color: #40A0F2;font-size: 26rpx;" @click="getMuBan()">
				<text style="color: #FF5A5F;">*请上传</text>
				<text style="color: #40A0F2;">整改复查记录表</text>
			</view>
			<!-- 附件上传 -->
			<view class="info_item" style="border: 0;">
				<upload-file
					:isSubmit="isSubmit"
					:imgList="addFormData.annex"
					:detailsImgList="detailsImgList"
					@my-upload-change="upLoadChange"
				></upload-file>
			</view>
			<!-- 审批备注 -->
			<view
				class="info_item"
				v-if="addFormData.is_approve == 1 && details_project_status == '23'"
				style="border-bottom: 0;"
			>
				<text class="all_text_title">审批备注</text>
				<textarea
					v-model="approval_remark"
					class="textera"
					maxlength="-1"
					auto-height="true"
				/>
			</view>
		</view>
		<!-- 底部按钮 -->
		<view class="bottom">
			<view v-if="addFormData.is_edit != '1'">
				<button
					class="bottom_btn"
					style="background: #CCCCCC; width: 380rpx;"
					form-type="reset"
					@click="handleSubmit('1')"
				>
					保存草稿
				</button>
				<button
					class="bottom_btn"
					style="background: linear-gradient(0deg, #037CE3, #2EB3FF); margin-top: -88rpx;margin-left: 50%;"
					form-type="submit"
					@click="handleSubmit('0')"
				>
					提交
				</button>
			</view>
			
			<!-- 可撤回时显示 -->
			<view class="bottom" v-if="addFormData.is_edit == 1 && addFormData.withdraw_status == 1 && addFormData.is_approve != 1">
				<button
					class="bottom_btn"
					@click="handleWithdraw()"
					style="background: #DD524D; width: 100%;"
					form-type="reset"
				>
					撤回
				</button>
			</view>
			
			<view v-if="addFormData.is_approve == 1 && details_project_status == '23' && addFormData.withdraw_status != 1">
				<button
					class="bottom_btn"
					style="background: #CCCCCC; width: 380rpx;"
					form-type="reset"
					@click="handleExamine('-1')"
				>
					驳回
				</button>
				<button
					class="bottom_btn"
					style="background: linear-gradient(0deg, #037CE3, #2EB3FF); margin-top: -88rpx;margin-left: 50%;"
					form-type="submit"
					@click="handleExamine('1')"
				>
					审批通过
				</button>
			</view>
			
			<!-- 可撤回时显示 -->
			<view class="bottom2" v-if="addFormData.is_approve == 1 && addFormData.withdraw_status == 1">
				<button
					class="bottom_btn2"
					@click="handleWithdraw()"
					style="background: #FF5A5F; margin-left: 0;"
					form-type="reset"
				>
					撤回
				</button>
				<button
					class="bottom_btn2"
					@click="handleExamine('-1')"
					style="background: #CCCCCC;margin-left: 33%;"
					form-type="reset"
				>
					驳回
				</button>
				<button
					class="bottom_btn2"
					style="background: linear-gradient(0deg, #037CE3, #2EB3FF);margin-left: 66%;"
					@click="handleExamine('1')"
					form-type="submit"
				>
					审批通过
				</button>
			</view>
			
		</view>
	</view>
</template>

<script>
import xiaolu from '@/components/xiaolu-signature/index.vue';
import UploadFile from '@/components/upload-file.vue';
import ProjectButton from '@/components/project-button.vue';
import StepButton from '@/components/step-button.vue';
export default {
	components: {
		UploadFile,
		ProjectButton,
		StepButton,
		xiaolu
	},
	data() {
		return {
			stepProcessList:{
					stage_code:'',
					project_id:''
					},
			project_id: '',
			v: '',
			date: '选择时间',
			list: [1, 1],
			addFormData: {
				annex: [],
				notifier: '',
				notice_time: '',
				existing_problems: ''
			},
			S_project_name: '',
			isSubmit: true,
			detailsImgList: [],
			submitImgList: [],
			approval_remark: '',
			details_project_status: '',
			token: '',
			member_id: '',
			company_id: ''
		};
	},
	async onLoad(options) {
		this.token = uni.getStorageSync('btlh_process_token') || '';
		this.member_id = uni.getStorageSync('btlh_process_member_id') || '';
		this.company_id = uni.getStorageSync('bthl_process_LoginCompanyId') || '';

		this.details_project_status = options.details_project_status || '';
		this.project_id = options.project_id || '';
		if (this.project_id) {
			this.getProjectDetails();
		}
	},
	// 开启微信发送给朋友
	//#ifdef MP-WEIXIN
	onShareAppMessage() {
		return{
			title:this.addFormData.project_name,
			path:'/packageProject/pages/project/fieldSurvey/reviewLog?project_id='+this.project_id+'&details_project_status='+this.details_project_status
		}
	},
	//#endif
	methods: {
		// 点击复制模板链接
		getMuBan(){
			uni.setClipboardData({
			    data: 'http://control.sxpz.vip/Template/整改复查记录表.doc',
			    success: function () {
			        uni.showToast({
			        	title:'复制成功'
			        })
			    }
			});
		},
		// 点击撤回
		async handleWithdraw(){
			const { data: res } = await this.$myRequest({
				url: 'Project/withdraw',
				method: 'GET',
				data: {
					member_id: this.member_id,
					token: this.token,
					company_id: this.company_id,
					project_id:this.project_id
				}
			});
			if (res.code != 200)
				return uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				});
				uni.navigateBack({
					delta:1
				})
		},
		// 审批
		async handleExamine(val) {
			const { data: res } = await this.$myRequest({
				url: 'Project/review_approval',
				method: 'POST',
				data: {
					member_id: this.member_id,
					token: this.token,
					company_id: this.company_id,

					project_id: this.project_id,
					approval_status: val,
					remark: this.approval_remark
				}
			});
			if (res.code != 200)
				return uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				});
			uni.showToast({
				title: res.datas.msg,
				icon: 'none'
			});
			/* uni.navigateTo({
				url: `/packageProject/pages/project/projectManagement`
			}); */
			uni.navigateBack({
				delta:1
			})
		},
		// 编辑提交
		async handleSubmit(val) {
			if (this.date != '选择时间') {
				this.addFormData.notice_time = this.date;
			}
			const { data: res } = await this.$myRequest({
				url: 'Project/review',
				method: 'POST',
				data: {
					member_id: this.member_id,
					token: this.token,
					company_id: this.company_id,
					project_id: this.project_id,

					is_draft: val,

					annex: JSON.stringify(this.submitImgList),

					notifier: this.addFormData.notifier,
					notice_time: this.addFormData.notice_time,
					existing_problems: this.addFormData.existing_problems
				}
			});
			if (res.code != 200)
				return uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				});
			uni.showToast({
				title: res.datas.msg,
				icon: 'none'
			});
			/* uni.navigateTo({
				url: `/packageProject/pages/project/projectManagement`
			}); */
			uni.navigateBack({
				delta:1
			})
		},
		// 获取项目详情
		async getProjectDetails() {
			const { data: res } = await this.$myRequest({
				url: 'Project/review_detail',
				method: 'POST',
				data: {
					member_id: this.member_id,
					token: this.token,
					company_id: this.company_id,

					project_id: this.project_id
				}
			});
			if (res.code != 200)
				return uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				});
			// 判断是否首次进入次流程
			if (res.datas.info.is_new != 1) {
				this.addFormData = res.datas.info;
			}else{
				this.addFormData.is_edit = res.datas.info.is_edit
			}
			// 判断禁用
			if (this.addFormData.is_draft != '1' && this.addFormData.is_edit == '1') {
				this.isSubmit = false;
			}
			this.stepProcessList.project_id = this.addFormData.project_id;
			this.stepProcessList.stage_code = this.addFormData.project_status;
			// 禁用值
			this.S_project_name = res.datas.info.project_name;

			// 处理时间
			if (this.addFormData.notice_time) {
				this.date = this.addFormData.notice_time;
			}
			// 处理文件
			if (this.addFormData.annex) {
				this.detailsImgList = this.addFormData.annex;
				this.submitImgList = this.addFormData.annex;
			}
			console.log('整改通知单', this.addFormData);
		},
		// 文件上传
		upLoadChange(data) {
			console.log('文件列表', data);
			this.submitImgList = data;
		},
		// 设置时间
		setDate(e) {
			this.date = e.detail.value;
		},
		// 删除条目
		deleteItem(index) {
			this.list.splice(index, 1);
		},
		// 签名
		async startSign1() {
			let s = await this.$refs.sig.getSyncSignature();
			this.v = s;
			console.log('组件版本', this.$refs.sig.VERSION);
			console.log('签名数据', s);
		},
		// 点击右下文件按钮
		fbtnClick() {
			console.log('22');
		},
		/* 
			点击返回 
			 */
		back() {
			// uni.navigateBack({
			// 	delta: 1
			// });
			uni.redirectTo({
				url:'/packageProject/pages/project/projectManagement'
			})
		}
	}
};
</script>

<style lang="scss">
.bottom2 {
		width: 100%;
	}
	.bottom_btn2 {
		width: 34%;
		height: 88rpx;
		border-radius: 0;
		position: fixed;
		bottom: 0;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
		z-index: 999;
	}	
	
.picker1 {
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #999999;
	margin-top: 42rpx;
}

.date {
	width: 32rpx;
	height: 32rpx;
	position: absolute;
	right: 51rpx;
	top: 100rpx;
}
.text2 {
	font-size: 25rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #333333;
	margin-top: 40rpx;
	margin-left: 200rpx;
	display: flex;
	flex-direction: row;
}
.text1 {
	font-size: 24rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #128bf1;
	margin-top: 21rpx;
}
.line_item {
	width: auto;
	height: 52rpx;
	border: 1rpx solid #ebebeb;
	line-height: 52rpx;
	text-align: center;
}
.line {
	font-size: 20rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #333333;
	display: flex;
	flex-direction: row;
}
.add_user {
	width: 170rpx;
	height: 54rpx;
	background: #40a0f2;
	border-radius: 27rpx;
	font-size: 24rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #ffffff;
	line-height: 54rpx;
	text-align: center;
	margin-left: 370rpx;
}

.fbtn {
	position: fixed;
	left: 592rpx;
	bottom: 120rpx;
	z-index: 5;

	image {
		width: 134rpx;
		height: 134rpx;
	}
}

.file_name {
	font-size: 26rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #999999;
	margin-left: 19rpx;
}

.uptext {
	font-size: 20rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #128bf1;
	margin-left: 10rpx;
}

.bottom {
	width: 100%;
	z-index: 999;
	position: fixed;
	bottom: 0;
}

.bottom_btn {
	width: 375rpx;
	height: 88rpx;
	margin-left: 0;
	border-radius: 0;
	font-size: 32rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #ffffff;
}

.info_item {
	width: 690rpx;
	height: auto;
	border-bottom: 1rpx solid #e3e3e3;
	margin-left: 30rpx;
	margin-top: 44rpx;
}

.head_text {
	width: 100%;
	height: 128rpx;
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #333333;
	line-height: 160rpx;
	text-align: center;
}
.textera {
	width: 690rpx;
	height: 225rpx;
	background: #f7f7f7;
	margin-top: 30rpx;
	padding-top: 20rpx;
	padding-bottom: 20rpx;
}
</style>
